<script type="text/javascript">
$(document).ready(function() {
 $('#calendar').fullCalendar({ 
         draggable: true, 
         events: "<?= site_url('user/attendance/get_attendance_details');?>", 
         eventDrop: function(event, delta) { 
            alert(event.title + ' was moved ' + delta + ' days\n' + 
               '(should probably update your database)'); 
         }, 
         loading: function(bool) { 
            if (bool) $('#loading').show(); 
            else $('#loading').hide(); 
         } 
      }); 
});
</script>
<?php 
$total_time = 0;
$tot = 0;
$present_days = 0;
?>
<div class="row-fluid">
<div class="span9">
<h3>Your daily attendance sheet for month of  <?php
//echo $this->uri->segment(5);
 echo $monthName = date("F", mktime(0, 0, 0, $this->uri->segment(5), 10));?></h3>
<table class="table table-striped table-hover table-condensed" width="100%">	
		<tr class="text-info">
			<td>Date</td>
			<td>Entry Time</td>
			<td>Exit Time</td>
			<td>Total Working Hours</td>			
		</tr>	
	<tbody>
	<?php 
	
	foreach($daily_sheets as $daily_sheet){?>
	<?php for($i=1;$i<=$num;$i++){
		
		if($i<10)
		{
		$day = 'day_0'.$i;	
		$date_id = '0'.$i;
		}
	else{
		$day = 'day_'.$i;
		$date_id = $i;
		}
		?>
		
	<tr <?php if($daily_sheet->$day=='sunday'){?> class="text-error error" <?php }?> >
		<td><?php echo date("F", mktime(0, 0, 0, $this->uri->segment(5), 10)).' '.$date_id?></td>
		<td>
		<?php 		
		$time_details = $this->attendance_model->get_time($daily_sheet->year_id,$daily_sheet->month_id,$date_id);
		if(!empty($time_details['entry_time'])){
		echo DATE("g:i a", STRTOTIME($time_details['entry_time']));
		}	
		?>
		</td>
		<td><?php 
		$absent = 0;
		if(!empty($time_details['exit_time'])){
		echo DATE("g:i a", STRTOTIME($time_details['exit_time']));}?></td>
		<td><?php echo $daily_sheet->$day;		
		// explode the time
		if(isset($daily_sheet->$day) && !empty($daily_sheet->$day) && $daily_sheet->$day!='sunday'){
		$present_days +=1 ;		
		$time_explode = explode(':',$daily_sheet->$day);
		 $tot_hr = $time_explode[0]*60*60;
		 $tot_min = $time_explode[1]*60;
		 $tot = $tot_hr + $tot_min;
		 $total_time += $tot;
		}
		elseif(empty($daily_sheet->$day) && $date_id <= date('d')){
			
			//echo ;
			
		}
		?></td>		
	</tr>
	<?php }}?>	
	</tbody>
</table>

</div>
<div class="span3">
<header>Monthly Status</header>
<b>No. of Working Days   : </b>25 days<br />
<b>Average Working Hr   : </b><?php 

if(isset($min_working_hr['min_working_hour'])){
echo $min_working_hr['min_working_hour'].'hrs';	
}else{
	echo 'No Salary has been defined';
}


?> 
<hr />
<b>Present : </b> <?php echo $present_days?> days<br/>
<b>Total Working Hr      : </b>  <?php 
$hours = floor($total_time / 3600);
$minutes = floor(($total_time / 60) % 60);
echo $sumtime = $hours .':'.$minutes;
?> hrs<br />

<?php 

?>
<b>Average :</b>  <?php 
if($present_days > 0){	
$avg_time = $total_time / $present_days;
$hr = floor($avg_time / 3600);
$min = floor(($avg_time / 60) % 60);
echo $hr.':'.$min;	
}else{
	echo '0';	
}

?>  

<header>Attendance Sheet</header>
<ul>
<?php foreach($attendance as $attend){?>
<li><a href="<?php echo site_url('user/attendance/index').'/'.$attend->year_id.'/'.$attend->month_id?>"><?php echo date("F",mktime(0, 0, 0,$attend->month_id, 10));?></a></li>
<?php }?>
</ul>
<br /><br />

<header>Salary Status for <?php echo date("F",mktime(0, 0, 0,$attend->month_id, 10));?></header>
<table width="100%">
<tr>
<td width="40%">My Salary</td>
<td width="60%">: Rs. <?php if(isset($my_salary['salary'])){echo $my_salary['salary'];} else {echo 'No Salary has been defined';}?></td>
</tr>

<tr>
<td width="40%">Per day</td>
<td width="60%">: Rs. <?php if(isset($my_salary['per_day_salary'])){echo $my_salary['per_day_salary'];} else {echo 'No Salary has been defined';}?></td>
</tr>
</table>
<hr />
<table>

<tr class="text-success" style="font-weight: bold">
<td>Receivable Salary</td>
<td class="text-error">: 
Rs. <?php if(isset($my_salary['per_day_salary'])){ 
$salary_receivable = ($my_salary['per_day_salary'] * $present_days);

if($salary_receivable > $my_salary['salary']){
$salary_receivable = $my_salary['salary'];
}
echo $salary_receivable;
 } 
 else {
 	echo 'No Salary has been defined';
	} ?>
	
</td>
</tr>
<tr>
	<td colspan="2">
		<center><small class="mutted">[Present (X) Per day Salary]</small></center>		
	</td>
	
</tr>
</table>
<br />
<br />

</div>
</div>